package tech.xyxy.layoutlearn

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setListeners()
    }

    private fun setListeners() {
        val views: List<View> = listOf(
            box_one_text,
            box_two_text,
            box_three_text,
            box_four_text,
            box_five_text,
            red_button,
            green_button,
            blue_button
        )
        for (view in views) {
            view.setOnClickListener() {
                colorView(view)
            }
        }
    }

    private fun colorView(view: View) {
        when (view.id) {
            R.id.box_one_text -> view.setBackgroundResource(android.R.color.holo_blue_bright)
            R.id.box_two_text -> view.setBackgroundResource(android.R.color.holo_blue_bright)
            R.id.box_three_text -> view.setBackgroundResource(android.R.color.holo_blue_bright)
            R.id.box_four_text -> view.setBackgroundResource(android.R.color.holo_blue_bright)
            R.id.box_five_text -> view.setBackgroundResource(android.R.color.holo_blue_bright)
            R.id.red_button -> view.setBackgroundResource(android.R.color.holo_red_light)
            R.id.green_button -> view.setBackgroundResource(android.R.color.holo_green_light)
            R.id.blue_button -> view.setBackgroundResource(android.R.color.holo_blue_light)
            else ->
                view.setBackgroundResource(android.R.color.black)

        }
    }
}
